import type from "./action-type";
import * as Api from "api/api";

export const setUsername = payload => {
  return {
    type: type.SET_USERNAME,
    payload
  };
};

export const setToken = payload => {
  return {
    type: type.SET_TOKEN,
    payload
  };
};

export const login = ({ username, token }) => {
  return f => {
    f(setUsername(username));
    f(setToken(token));
  };
};

export const logout = () => {
  return async f => {
    const res = await Api.logout();
    f(setToken(""));
  };
};
